﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;

namespace TextListContentPipelineExtension
{
    /// <summary>
    /// This class is the third stage in our custom Content Pipeline extension. This is where
    /// the XNB gets written out. Note that you need to apply the ContentTypeWriterAttribute to
    /// this class. Note also that you should have overrides of the Write method, the GetRuntimeReader
    /// method, and the GetRuntimeType method. People often forget the GetRuntimeReader and/or
    /// GetRuntimeType overrides or else get them wrong, which will give you exceptions when trying to
    /// load the content in-game (seriously, try commenting out one or both and watch the errors fly!).
    /// 
    /// This is the last part of the Content Pipeline Extension project, but it's not the end. From here
    /// we switch from the land of build-time to the land of run-time. There we have the run-time type, which
    /// in our case is the TextList class. We also have the ContentReader, which reads in the stuff that this
    /// class writes out. The ContentReader is the final stage of a custom Content Pipeline extension. Without
    /// it there's nothing that can read in your content.
    /// </summary>
    [ContentTypeWriter()]
    public class TextListContentWriter : ContentTypeWriter<TextListContent>
    {
        /// <summary>
        /// Writes out the TextListContent to an XNB file. This calls into a method in the TextListContent class
        /// itself. You could implement the writing logic here, but I think this is a cleaner way of doing this
        /// since you are more likely to remember to update the writer (and the reader) if you change the content
        /// class if you have implemented the writer in the content class itself.
        /// </summary>
        /// <param name="output">The Content Pipeline-supplied ContentWriter.</param>
        /// <param name="value">The TextListContent from our TextListContentProcessor.</param>
        protected override void Write(ContentWriter output, TextListContent value)
        {
            value.Write(output);
        }

        /// <summary>
        /// Return the assembly-qualified name of the runtime loader for the type. This is important!
        /// </summary>
        /// <param name="targetPlatform">
        /// The platform (PC, Xbox 360, or WP7) that this is being written for. Useful
        /// in the event that you want to specify different readers for different platforms.
        /// </param>
        /// <returns>The assembly-qualified name of the runtime loader for the type.</returns>
        public override string GetRuntimeReader(TargetPlatform targetPlatform)
        {
            return "TextListLib.TextListReader, TextListLib";
        }

        /// <summary>
        /// Return the assembly-qualified name of the runtime type for this content. This is also important!
        /// </summary>
        /// <param name="targetPlatform">
        /// The platform (PC, Xbox 360, or WP7) that this is being written for. Useful
        /// in the event that you want to specify different runtime types for different platforms.
        /// </param>
        /// <returns>The assembly-qualified name of the runtime type for this content.</returns>
        public override string GetRuntimeType(TargetPlatform targetPlatform)
        {
            return "TextListLib.TextList, TextListLib";
        }
    }
}
